home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 February / LiquidLibrary 2005 February - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_frsd.ps < prev    next >
Text File  |  2003-01-03  |  3KB  |  73 lines

  1. %    Copyright (C) 2000 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % Implementation of ReusableStreamDecode filter.
  7. % This file must be loaded after gs_lev2.ps and gs_res.ps.
  8.  
  9. level2dict begin
  10.  
  11. % ------ ReusableStreamDecode filter ------ %
  12.  
  13. /.reusablestreamdecode {    % <source> <dict> .reusablestreamdecode <file>
  14.                 % <source> .reusablestreamdecode <file>
  15.         % Collect the filter parameters.
  16.   dup type /dicttype eq { 2 copy } { dup 0 dict } ifelse
  17.   dup .rsdparams
  18.         % Construct the filter pipeline.
  19.         % The very first filter should use the value of CloseSource
  20.         % from the RSD dictionary; all the others should have
  21.         % CloseSource = true.
  22.         % Stack: source dict filters parms
  23.   2 index /CloseSource .knownget not { false } if 5 -1 roll
  24.         % Stack: dict filters parms CloseSource source
  25.   0 1 5 index length 1 sub {
  26.     4 index 1 index get
  27.         % Stack: dict filters parms CloseSource source index filtname
  28.     4 index null eq {
  29.       0 dict
  30.     } {
  31.       4 index 2 index get dup null eq { pop } if
  32.     } ifelse
  33.     3 -1 roll pop exch filter
  34.     exch pop true exch        % set CloseSource for further filters
  35.   } for
  36.         % If AsyncRead is true, try to create the filter directly.
  37.         % Stack: dict filters parms CloseSource source
  38.   4 index /AsyncRead .knownget not { false } if {
  39.     1 index { .reusablestream } .internalstopped
  40.   } {
  41.     null true
  42.   } ifelse {
  43.     pop
  44.         % No luck.  Read the entire contents of the stream now.
  45.     dup type /filetype ne {
  46.         % Make a stream from a procedure or string data source.
  47.       0 () .subfiledecode
  48.     } if
  49.     10 dict exch {
  50.         % Stack: dict filters parms CloseSource contdict file
  51.       dup 1000 string readstring
  52.       3 index dup length 4 -1 roll put not { exit } if
  53.     } loop pop
  54.         % Concatenate the contents into one big string.
  55.         % Stack: dict filters parms CloseSource contdict
  56.     0 1 index { length exch pop add } forall
  57.     .bigstring exch {
  58.         % Stack: dict filters parms CloseSource string index substring
  59.       exch 1000 mul exch 2 index 3 1 roll putinterval
  60.     } forall
  61.         % Now create the stream on the string.
  62.     1 index .reusablestream
  63.   } if
  64.         % We created the stream successfully: clean up.
  65.   4 { exch pop } repeat
  66.   1 index type /dicttype eq { exch pop } if exch pop
  67. } odef
  68.  
  69. filterdict /ReusableStreamDecode /.reusablestreamdecode load put
  70.  
  71. end            % level2dict
  72.